#include <bits/stdc++.h>

using namespace std;
int T;

int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin >> T;
    for (int i = 1; i <= T; i++)
    {
        int n,m,L,V,num=0,ans=0;
        cin >> n >> m >> L >> V;
        for (int j = 1; j <= n; j++)
        {
            int d,v,a;
            cin >> d >> v >> a;
            if (v <= V)
            {
                num ++;
            }
        }
        ans = m-1;
        cout << num << " " << ans << endl;
    }

    return 0;
}
